package com.plug.common.entity;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 响应结果模型
 *
 * @author Archx[archx@foxmail.com]
 * @date 2016/5/17 0017
 */
public class RespResult implements Serializable {

    /**
     * 返回代码
     * <p/>
     * 系统应该统一制定一份返回代码<br/>
     * 遵循一般约定 0 表示无错误 <br/>
     */
    protected int code;

    /**
     * 返回消息
     */
    protected String message;

    /**
     * 返回结果对象
     */
    protected Object result;

    /**
     * 返回数据
     */
    protected Map<String, Object> data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getResult() {
        return result;
    }

    public void setResult(Object result) {
        this.result = result;
    }

    public Map<String, Object> getData() {
        return data;
    }

    public void setData(Map<String, Object> data) {
        if (this.data == null)
            this.data = data;
        else
            this.data.putAll(data);
    }

    /**
     * 添加返回数据
     *
     * @param key   Key
     * @param value 值
     * @return this
     */
    public RespResult putData(String key, Object value) {
        if (this.data == null) {
            this.data = new HashMap<>();
        }
        this.data.put(key, value);
        return this;
    }
}
